//
//  ViewController.m
//  3-8
//
//  Created by mac on 16-3-8.
//  Copyright (c) 2016年 mac. All rights reserved.
//

#import "ViewController.h"
#import "QQmassage.h"
@interface ViewController ()<UITableViewDataSource>
@property (retain, nonatomic) IBOutlet UITableView *tabelView;
@property(nonatomic,strong)NSArray * massage;

@end

@implementation ViewController
//重写massage的get方法，懒加载
-(NSArray *)massage
{
    if(_massage == nil)
    {
        //读取plist文件
        NSString * path = [[NSBundle mainBundle]pathForResource:@"massage.plist" ofType:nil];
        //加载
        NSArray * dictMassage = [NSArray arrayWithContentsOfFile:path];
        //封装数据模型
        NSMutableArray * massageArr =[NSMutableArray array];
        for (NSDictionary * massageDict in dictMassage)
        {
            //创建模型对象
            QQmassage * massage = [QQmassage massageWithDict:massageDict];
            [massageArr addObject:massage];
        }
        _massage = massageArr;
    }
    return _massage;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.tabelView.dataSource = self;
}
//返回组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

//返回行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //return 3;
    //QQmassage * massage = self.massage[section];
    return self.massage.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    //cell.textLabel.text = @"你好，你吃翔了嚒？";
    QQmassage * massage = self.massage[indexPath.row];
     cell.imageView.image = [UIImage imageNamed:massage.headMassage];
    cell.textLabel.text = massage.massage;
    return cell;
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [_tabelView release];
    [super dealloc];
}
@end
